package com.huiminpay.merchant.controller;

import com.huiminpay.common.cache.domain.PageVO;
import com.huiminpay.common.cache.util.SecurityUtil;
import com.huiminpay.merchant.service.StoreService;
import com.huiminpay.transaction.api.dto.QRCodeDto;
import com.yh.merchant.api.StoreServiceApi;
import com.yh.merchant.dto.StoreDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: HWW
 * @Date: 2021/8/3110:20
 * @Desc:
 */
@RestController
@Api(value = "商户平台‐门店管理", tags = "商户平台‐门店管理", description = "商户平台‐门店的增删改查")
@Slf4j
public class StoreController {

    @Reference
    private StoreServiceApi storeServiceApi;

    @Autowired
    private StoreService storeService;



    @ApiOperation("分页条件查询商户下门店")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "页码", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = true, dataType = "Integer", paramType = "query")})

    @GetMapping("/my/stores/merchants/page")
    public PageVO<StoreDTO> queryStoreByPage(@RequestParam Integer pageNo, @RequestParam Integer
            pageSize) {
        //解析token,取出当前登录的商户ID
        Long merchantId = SecurityUtil.getMerchantId();
        StoreDTO storeDTO = new StoreDTO();
        storeDTO.setMerchantId(merchantId);
        PageVO<StoreDTO> storeDTOS = storeServiceApi.queryStoreByPage(storeDTO, pageNo, pageSize);
        return storeDTOS;
    }

    @ApiOperation("生成商户应用门店二维码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appId", value = "商户应用id", required = true, dataType = "String", paramType = "path"),
            @ApiImplicitParam(name = "storeId", value = "商户门店id", required = true, dataType = "String", paramType = "path"),
    })
    @GetMapping(value = "/my/apps/{appId}/stores/{storeId}/app‐store‐qrcode")
    public String createCScanBStoreQRCode(@PathVariable String appId, @PathVariable Long storeId) throws Exception {
        //解析token,取出当前登录的商户ID
        Long merchantId = SecurityUtil.getMerchantId();

        QRCodeDto qrCodeDto = new QRCodeDto();
        qrCodeDto.setAppId(appId);
        qrCodeDto.setStoreId(storeId);
        qrCodeDto.setMerchantId(merchantId);
        String storeQRCode = storeService.getStoreQRCode(qrCodeDto);

        return storeQRCode;
    }
}
